package com.zshan.clinic.web.controller.clinic;


import com.zshan.clinic.admin.entity.vo.ClinicDeptSelectVo;
import com.zshan.clinic.admin.entity.vo.ClinicDeptVo;
import com.zshan.clinic.admin.entity.vo.ClinicRoomVo;
import com.zshan.clinic.admin.service.clinic.ClinicDeptService;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.ClinicDept;
import com.zshan.clinic.database.model.ClinicDeptRoom;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 诊所科室
 */
@RestController
@RequestMapping("/clinic/dept")
public class ClinicDeptController extends AbstractController {

    @Autowired
    private ClinicDeptService clinicDeptService;

    /**
     * 获取科室下拉框数据
     * @return
     */
    @GetMapping("/getSelectList")
    public RestResp<List<ClinicDeptSelectVo>> getSelectList(){
        UserInfo userInfo = getUserInfo();
        List<ClinicDeptSelectVo> selectList = clinicDeptService.getSelectList(userInfo.getClinicId());
        return RestResp.SUCCESS(selectList);
    }

    /**
     * 获取科室列表
     * @param deptName 科室名
     * @return
     */
    @GetMapping("/getDeptList")
    public RestResp<PageInfo<ClinicDeptVo>> getDeptList(@RequestParam(name = "deptName",required = false) String deptName,
                                                        @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize){
        UserInfo userInfo = getUserInfo();
        PageInfo<ClinicDeptVo> pageInfo = clinicDeptService.getDeptList(userInfo.getClinicId(),deptName,pageNo,pageSize);
        return RestResp.SUCCESS(pageInfo);
    }

    /**
     * 添加科室
     * @return
     */
    @PostMapping(value = "/addDept")
    public RestResp<Void> addDept(@RequestBody ClinicDept clinicDept) {
        UserInfo userInfo = getUserInfo();
        clinicDept.setCreateUserId(userInfo.getEmpId());
        clinicDept.setCreateBy(userInfo.getEmpName());
        clinicDept.setClinicId(userInfo.getClinicId());
        clinicDeptService.addDept(clinicDept);
        return RestResp.SUCCESS();
    }

    /**
     * 修改科室
     * @return
     */
    @PostMapping(value = "/updateDept")
    public RestResp<Void> updateDept(@RequestBody ClinicDept clinicDept) {
        UserInfo userInfo = getUserInfo();
        clinicDept.setUpdateUserId(userInfo.getEmpId());
        clinicDept.setUpdateBy(userInfo.getEmpName());
        clinicDept.setClinicId(userInfo.getClinicId());
        clinicDeptService.updateDept(clinicDept);
        return RestResp.SUCCESS();
    }

    /**
     * 删除科室
     * @return
     */
    @PostMapping(value = "/deleteDept")
    public RestResp<Void> deleteDept(@RequestBody ClinicDept clinicDept) {
        UserInfo userInfo = getUserInfo();
        clinicDept.setUpdateUserId(userInfo.getEmpId());
        clinicDept.setUpdateBy(userInfo.getEmpName());
        clinicDept.setClinicId(userInfo.getClinicId());
        clinicDeptService.deleteDept(clinicDept);
        return RestResp.SUCCESS();
    }

    /**
     * 启用科室
     * @return
     */
    @PostMapping(value = "/enableDept")
    public RestResp<Void> enableDept(@RequestBody ClinicDept clinicDept) {
        UserInfo userInfo = getUserInfo();
        clinicDept.setUpdateUserId(userInfo.getEmpId());
        clinicDept.setUpdateBy(userInfo.getEmpName());
        clinicDept.setClinicId(userInfo.getClinicId());
        clinicDeptService.enableDept(clinicDept);
        return RestResp.SUCCESS();
    }

    /**
     * 停用科室
     * @return
     */
    @PostMapping(value = "/disableDept")
    public RestResp<Void> disableDept(@RequestBody ClinicDept clinicDept) {
        UserInfo userInfo = getUserInfo();
        clinicDept.setUpdateUserId(userInfo.getEmpId());
        clinicDept.setUpdateBy(userInfo.getEmpName());
        clinicDept.setClinicId(userInfo.getClinicId());
        clinicDeptService.disableDept(clinicDept);
        return RestResp.SUCCESS();
    }

    /**
     * 查询诊室列表
     * @param
     * @return
     */
    @GetMapping("/getRoomList")
    public RestResp<PageInfo<ClinicRoomVo>> getRoomList(@RequestParam(name = "deptId",required = false) Long deptId,
                                                        @RequestParam(name = "roomName",required = false) String roomName,
                                                        @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize){
        UserInfo userInfo = getUserInfo();
        PageInfo<ClinicRoomVo> roomList = clinicDeptService.getRoomList(userInfo.getClinicId(),deptId,roomName,pageNo,pageSize);
        return RestResp.SUCCESS(roomList);
    }

    /**
     * 添加诊室
     * @return
     */
    @PostMapping(value = "/addRoom")
    public RestResp<Void> addRoom(@RequestBody ClinicDeptRoom clinicDeptRoom) {
        UserInfo userInfo = getUserInfo();
        clinicDeptRoom.setCreateUserId(userInfo.getEmpId());
        clinicDeptRoom.setCreateBy(userInfo.getEmpName());
        clinicDeptRoom.setClinicId(userInfo.getClinicId());
        clinicDeptService.addRoom(clinicDeptRoom);
        return RestResp.SUCCESS();
    }

    /**
     * 编辑诊室
     * @return
     */
    @PostMapping(value = "/updateRoom")
    public RestResp<Void> updateRoom(@RequestBody ClinicDeptRoom clinicDeptRoom) {
        UserInfo userInfo = getUserInfo();
        clinicDeptRoom.setUpdateUserId(userInfo.getEmpId());
        clinicDeptRoom.setUpdateBy(userInfo.getEmpName());
        clinicDeptRoom.setClinicId(userInfo.getClinicId());
        clinicDeptService.updateRoom(clinicDeptRoom);
        return RestResp.SUCCESS();
    }

    /**
     * 删除诊室
     * @return
     */
    @PostMapping(value = "/deleteRoom")
    public RestResp<Void> deleteRoom(@RequestBody ClinicDeptRoom clinicDeptRoom) {
        UserInfo userInfo = getUserInfo();
        clinicDeptRoom.setUpdateUserId(userInfo.getEmpId());
        clinicDeptRoom.setUpdateBy(userInfo.getEmpName());
        clinicDeptRoom.setClinicId(userInfo.getClinicId());
        clinicDeptService.deleteRoom(clinicDeptRoom);
        return RestResp.SUCCESS();
    }

    /**
     * 启用诊室
     * @return
     */
    @PostMapping(value = "/enableRoom")
    public RestResp<Void> enableRoom(@RequestBody ClinicDeptRoom clinicDeptRoom) {
        UserInfo userInfo = getUserInfo();
        clinicDeptRoom.setUpdateUserId(userInfo.getEmpId());
        clinicDeptRoom.setUpdateBy(userInfo.getEmpName());
        clinicDeptRoom.setClinicId(userInfo.getClinicId());
        clinicDeptService.enableRoom(clinicDeptRoom);
        return RestResp.SUCCESS();
    }

    /**
     * 停用诊室
     * @return
     */
    @PostMapping(value = "/disableRoom")
    public RestResp<Void> disableRoom(@RequestBody ClinicDeptRoom clinicDeptRoom) {
        UserInfo userInfo = getUserInfo();
        clinicDeptRoom.setUpdateUserId(userInfo.getEmpId());
        clinicDeptRoom.setUpdateBy(userInfo.getEmpName());
        clinicDeptRoom.setClinicId(userInfo.getClinicId());
        clinicDeptService.disableRoom(clinicDeptRoom);
        return RestResp.SUCCESS();
    }

}
